<?php

namespace mpend\modules\demand\models;

use Yii;
use common\helpers\ArrayHelper;
use common\helpers\Url;

/**
 * 比赛文字直播信息模型
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class CategorySearch extends \mpend\models\searchs\DemandCategorySearch {

    public function getMpRoute() {
        return [
            'type' => 'push',
            'route' => Url::to([
                '/pages/needs/main',
                'id' => $this->id
            ]),
            'params' => [
                'title' => $this->name
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'title' => 'name',
            'icon',
            'cover' => 'icon',
            'description',
            'link' => 'mpPage',
            'route' => 'mpRoute',
        ];
    }

    public static function getOptionsList() {
        $data = static::find()->active(static::STATUS_ACTIVE)->orderBy([
            'navbar' => SORT_DESC,
            'listorder' => SORT_DESC,
        ])->all();
        $categories = [];
        foreach ($data as $item) {
            $categories[] = [
                'text' => $item->name,
                'value' => $item->id,
            ];
        }
        return $categories; //ArrayHelper::map($data, 'id', 'name');
    }

}
